﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using QuanLyBanHang.DTO;
using QuanLyBanHang.BLL;
namespace QuanLyBanHang
{
    public partial class SanPham : Form
    {
        SanPhamcs sp = new SanPhamcs();

       
        public SanPham()
        {
            InitializeComponent();
            
           
        }
        //DUA DU LIEU VAO TEXTBOX
        private void TaoSanPham()
        {
            SanPhamcs.MaSanPham = textBox1.Text;
            SanPhamcs.TenSanPham = textBox2.Text;
            SanPhamcs.DonViTinh = textBox3.Text;
            SanPhamcs.SoLuong = Convert.ToInt32(textBox4.Text);
        }
        private void SanPham_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = SanPhamBLL.LayTatCaSanPham(sp);
            //dataGridView1_CellContentClick( sender,  e);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           
           int i = e.RowIndex;
            textBox1.Text = dataGridView1.Rows[i].Cells["MaSP"].Value.ToString();
            textBox2.Text = dataGridView1.Rows[i].Cells["TenSP"].Value.ToString();
            textBox3.Text = dataGridView1.Rows[i].Cells["DonViTinh"].Value.ToString();
            textBox4.Text = dataGridView1.Rows[i].Cells["DonGia"].Value.ToString();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            TaoSanPham();
            MessageBox.Show("Them Thanh cong "+SanPhamBLL.ThemSanPham(sp));
            SanPham_Load(sender, e);
        }
         private void button3_Click(object sender, EventArgs e)
        {
            TaoSanPham();
            //MessageBox.Show("Xoa Thanh cong " + SanPhamBLL.XoaSanPham(sp));
            SanPhamBLL.XoaSanPham(sp);
            MessageBox.Show("Ban Chac Muon xoa khong", "Thong Bao", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            SanPham_Load(sender, e);
        }
         private void button2_Click(object sender, EventArgs e)
         {
             TaoSanPham();
             SanPhamBLL.SuaSanPham(sp);
             MessageBox.Show("Ban muon sua ko ", "Thong Bao", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             SanPham_Load(sender, e);

         }


        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

      
        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

     
        
       

       

    }
}
